# Config reload
bind r source-file ~/.tmux.conf \; display "Tmux config updated"


# ----- Prefix -----

unbind-key C-b
set-option -g prefix C-x
bind-key C-x send-prefix


# ----- Panes -----

# Key bindings for switching panes
bind -n M-h select-pane -L # left
bind -n M-l select-pane -R # right
bind -n M-k select-pane -U # up
bind -n M-j select-pane -D # down

# Key bindings for creating panes
bind-key 1 split-window -h # horizontal
bind-key 2 split-window -v # verticle

# Seperator colors for current pane
set-option -g pane-active-border-style fg=blue # foreground
# set-option -g pane-active-border-style bg=white # background

# Seperator color for other panes
set-option -g pane-border-style fg=cyan # foreground
# set-option -g pane-border-style bg=white # background

# Key bindings for closing panes
bind-key 0 kill-pane

# Key bindings for adjusting panes size
bind-key K resize-pane -U # up
bind-key J resize-pane -D # down
bind-key L resize-pane -R # right
bind-key H resize-pane -L # left
bind-key m resize-pane -Z # maximize

# Key bindings for navigating between panes
bind-key k select-pane -U # up
bind-key j select-pane -D # down
bind-key l select-pane -R # right
bind-key h select-pane -L # left

# ----- Status Bar -----

# Colors for the status bar
set -g status-bg 'black' # background
set -g status-fg 'white' # foreground

# Contents on the right of the status bar
set -g status-right "#[fg=magenta,bold] #{prefix_highlight}#[fg=red,bold]CPU: #{cpu_percentage} #[fg=blue]Battery: #{battery_percentage} #[fg=green]%a %Y:%m:%d %H:%M:%S "
set -g status-interval 1 # refresh every second
set -g status-right-length 100 # maximum length for the right content of the status bar

# Contents on the left of the status bar
set -g status-left "#[fg=yellow,bold] ❐ #S   " # show the current session
set -g status-left-length 8 # maximum length for the left content of the status bar

# Position of the status bar
# (top/bottom)
set -g status-position bottom

# Position of the window status
# (left/centre/right)
set -g status-justify left

# Color of the status bar message
# bg: background / fg: foreground
set-option -g message-style bg=blue,fg=white

# Key binding for toggle status bar
bind-key s set status


# ----- Windows -----

# Status format for the current window
setw -g window-status-current-format '#[fg=blue,bold]✔ #[fg=white,bold]#W'

# Status format for other windows
setw -g window-status-format '#[fg=white]#I #W'

# Seperator between each window names
set -wg window-status-separator '  '

# Show alert if other window changes?
setw -g monitor-activity off

# Should automatically rename other windows based on the current program?
set -g automatic-rename on

# Key binding for closing windows
bind-key q kill-window

# Key binding for switching windows
bind-key C-h previous-window
bind-key C-l next-window


# ----- More options -----

# History limit for scrolling back
set -g history-limit 5000

# Use mouse to switch windows, adjust panes, etc...
set -g mouse on

# True color support
# (True color support only shows effect if your terminal emulator supports true color)
set -g default-terminal xterm-256color
set-option -ga terminal-overrides ",*256col*:Tc"

# Delay after escape key is passed into the program
set -s escape-time 0

# Use vi styled keys for scrolling & copying
set-window-option -g mode-keys vi


# ----- Plugins -----

# Tmux plugin manager
# (REQUIRED FOR USING PLUGINS)
# (do not remove)
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'

# Built-in plugins of p-z-l/magicTmux
# (recommended for better experience)
set -g @plugin 'tmux-plugins/tmux-battery'
set -g @plugin 'tmux-plugins/tmux-cpu'
set -g @plugin 'tmux-plugins/tmux-prefix-highlight'


# tmux-prefix_highlight configs
set -g @prefix_highlight_fg 'magenta' # default is 'colour231'
set -g @prefix_highlight_bg 'black' # default is 'colour04'

# Other plugins choices :
# (<prefix> + I to install/upgrade plugins, tmux will freeze for several seconds during install)

# Display online status on your status bar:
# set -g @plugin 'tmux-plugins/tmux-online-status'

# Restoring windows when starting tmux:
# set -g @plugin 'tmux-plugins/tmux-resurrect'
# set -g @plugin 'tmux-plugins/tmux-continuum'

# Easy logging and screen capturing for Tmux.
# set -g @plugin 'tmux-plugins/tmux-logging'

# A plugin that enhances tmux search:
# set -g @plugin 'tmux-plugins/tmux-copycat'

# Tmux key bindings for quick opening of a highlighted file or url:
# set -g @plugin 'tmux-plugins/tmux-open'

# Tmux plugin for copying to system clipboard. Works on OSX, Linux and Cygwin:
# set -g @plugin 'tmux-plugins/tmux-yank'

# Tmux plugin to monitor upload and download speed of one or all interfaces:
# set -g @plugin 'tmux-plugins/tmux-net-speed'

# Plugin that counts files on a specific mail directory
# set -g @plugin 'tmux-plugins/tmux-maildir-counter'

# A sidebar with the directory tree for the current path. Tries to make tmux more IDE like.
# set -g @plugin 'tmux-plugins/tmux-sidebar'

# Quickly open any url on your terminal window!
# set -g @plugin 'tmux-plugins/tmux-urlview'

# Quickly open any path on your temrinal window in your $EDITOR of choice!
# set -g @plugin 'jbnicolai/tmux-fpp'

# Lightweight tmux utils for manipulating sessions
# set -g @plugin 'tmux-plugins/tmux-sessionist'

# Initialize TMUX plugin manager
# (REQUIRED FOR USING PLUGINS)
# (keep this line at the very bottom of tmux.conf)
run -b '~/.tmux/plugins/tpm/tpm'
